package com.denlaku.longan.service.impl;

import com.denlaku.longan.BizModule;
import com.denlaku.longan.anno.RequiredTx;
import com.denlaku.longan.repository.DimensionRepository;
import com.denlaku.longan.service.DimensionService;
import com.denlaku.longan.util.SnowflakeUtils;
import com.denlaku.longan.vo.Dimension;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author tianx
 */
@Service
public class DimensionServiceImpl implements DimensionService {
	@Autowired
	private DimensionRepository dimensionRepository;

	@Override
	@RequiredTx
	public void batchAdd(List<Dimension> dimensionList) {
		if (CollectionUtils.isNotEmpty(dimensionList)) {
			ListUtils.emptyIfNull(dimensionList).forEach(dimension -> dimension.setId(SnowflakeUtils.nextId()));
			dimensionRepository.batchAdd(dimensionList);
		}
	}

	@Override
	@RequiredTx
	public void delete(Long tenantId, List<Long> componentIds) {
		dimensionRepository.delete(tenantId, componentIds);
	}

	@Override
	public List<Dimension> list(Long tenantId, List<Long> componentIds) {
		return dimensionRepository.list(tenantId, componentIds);
	}

}
